package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description NusingProjectController
 *
 * @author zhangyan
 * @time 2024/10/15
 */

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NusingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            String name,
            @ApiParam(value = "状态 0-禁用 1-启用")
            Integer status,
            @ApiParam(value = "页码")
            @RequestParam(value = "pageNum", defaultValue = "1")
            Integer pageNum,
            @ApiParam(value = "每页条数")
            @RequestParam(value = "pageSize", defaultValue = "10")
            Integer pageSize
    ) {
        logger.info("分页查询护理项目列表，参数：name={},status={},pageNum={},pageSize={}", name, status, pageNum, pageSize);
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.add(nursingProjectDTO);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("数据回显")
    public ResponseResult<NursingProjectVo> getById(
            @PathVariable("id") Long id) {
        NursingProjectVo nursingProject = nursingProjectService.getById(id);
        return success(nursingProject);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(
            @ApiParam(value = "修改护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.update(nursingProjectDTO);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("状态修改")
    public ResponseResult status(
            @ApiParam(value = "项目id", required = true)
            @PathVariable Long id,
            @ApiParam(value = "状态 0-禁用 1-启用", defaultValue = "1")
            @PathVariable Integer status) {
        nursingProjectService.updateStatus(id, status);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public ResponseResult delete( @PathVariable Long id) {
        nursingProjectService.removeById(id);
        return success();
    }
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAll(){
        List<NursingProjectVo> nursingProjectVoList =  nursingProjectService.getAll();
        return success(nursingProjectVoList);
    }
}
